/*
 * Powered By Rubyliu
 * QQ:876181
 * Since 2012 - 2012
 */

package com.bzzoneit.newsys.service.admin.impl;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bzzoneit.newsys.dao.admin.LogMapper;
import com.bzzoneit.newsys.entity.admin.Log;
import com.bzzoneit.newsys.service.admin.LogService;
import com.bzzoneit.newsys.utils.page.Page;

/**
 * @author Ruby liu
 * @version 1.0
 * @since 1.0
 */@Service
public class LogServiceImpl implements LogService {
	
	protected static Logger logger =  LoggerFactory.getLogger("service");
	
	@Autowired
	private LogMapper logMapper;
	

	public void insertLog(Log  log){
		logMapper.insertOne(log);
	}
	public void updateLog(Log  log){
		logMapper.updateOne(log);
	}
	public void deleteLog(long id){
		logMapper.deleteOne(id);
	}
	
	public Log selectLog(long id){
	  return 	logMapper.selectOne(id);
	}
	
	public Page<Log> getLogList(Page<Log> page){
		int pg = page.getPageNo();
		int pz = page.getNumPerPage();
		Log log=page.getT();
		int offset = 0;
		int limit = 0;
		if (pg > 0)
			offset = (pg - 1) * pz;
		else
			offset = 0;
		limit = pz;
		String orderString="";		
		if(StringUtils.isNotEmpty(page.getOrderBy())){
			orderString=page.getOrderBy();
			if(StringUtils.isNotEmpty(page.getOrder())){
				orderString+=" "+page.getOrder();
			}
			else{
				orderString+=" asc";
			}
			
		}
		else{
			orderString=" id desc"; 
		}	
		log.setOrderString(orderString);
		List<Log> result = logMapper.findLogPage(new RowBounds(offset, limit),log);
		page.setResult(result);
		page.setTotalCount(logMapper.findLogPagecount(log));
		return page;
	}
}